-module(game_sup).
-behaviour(supervisor).
-export([start_link/1,init/1,start/0]).
-include("common.hrl").

start_link(Data) ->
    supervisor:start_link({local, ?MODULE}, ?MODULE, Data).

start() ->
    ?MODULE:start_link().

init([Host,Port,Usr,Psw,Database,Code,NetPort]) ->
	DbData = [?DB,Host,Port,Usr,Psw,Database, fun(_, _, _, _) -> ok end,Code],
	SvrList = [	
			   {mysql_server, {mysql, start_link, DbData}, permanent, 2000, worker, [mysql]},
			   
			   {dbm_server, {dbm_svr, start_link, [[Host,Port,Usr,Psw,Database,Code]]}, permanent, 2000, worker, [dbm_svr]},
			   {key_server, {key_svr, start_link, [[Host,Port,Usr,Psw,Database,Code]]}, permanent, 2000, worker, [key_svr]},
			   
			   {login,		{world_svr,start_link,[login,fun_login]},permanent, 5000, worker, [world_svr]},
			   {game_center, {world_svr,start_link,[game_center,fun_game_center]},permanent, 5000, worker, [world_svr]},
			   {http_server, {world_svr, start_link,[http_server,fun_http_server]}, permanent, 5000, worker, [world_svr]},
			   {http_client, {world_svr, start_link,[http_client,fun_http_client]}, permanent, 5000, worker, [world_svr]},
			   {my_net_svr, {my_net_svr, start_link, [[NetPort]]}, permanent, 5000, worker, [my_net_svr]},
			   {my_net_sup, {my_net_sup, start_link, []}, permanent, 5000, supervisor, [my_net_sup]},
			   {room_ctr, {room_ctr, start_link, []}, permanent, 5000, worker, [room_ctr]},
			   {room_sup, {room_sup, start_link, []}, permanent, 5000, supervisor, [room_sup]}
			  ],
	RestartStrategy = {one_for_one, 3, 10},
	{ok, {RestartStrategy, SvrList}}.